package com.sunshine.lnuplusweb.service.Impl;

import com.sunshine.lnuplusweb.dao.UserMapper;
import com.sunshine.lnuplusweb.entities.User;
import com.sunshine.lnuplusweb.service.UserService;
import com.sunshine.lnuplusweb.utils.CryptoUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 用户服务实现类
 * 千万记住要注入SpringBoot容器中！
 */
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public int login(String userId, String password) {
        return userMapper.login(CryptoUtils.encrypByMD5(userId), CryptoUtils.encrypt(password, CryptoUtils.encrypByMD5(userId) + CryptoUtils.CipherMode));
    }

    @Override
    public int getUserCountById(String userId) {
        return userMapper.getUserCountById(CryptoUtils.encrypByMD5(userId));
    }

    @Override
    public User getUserById(String userId) {
        return userMapper.getUserById(CryptoUtils.encrypByMD5(userId));
    }

    @Override
    public void register(String userId, String password) {
        userMapper.register(CryptoUtils.encrypByMD5(userId), CryptoUtils.encrypt(password, CryptoUtils.encrypByMD5(userId) + CryptoUtils.CipherMode));
    }

    /**
     * 为该用户添加一个课表
     * @param scheduleId    课表id
     */
    @Override
    public void addSchedule(int scheduleId) {

    }
}
